<?php
	$content_xml .= '
			<table:table table:name="Table1"
				table:style-name="Table1">
				<table:table-column table:style-name="Table1.A" />
				<table:table-column table:style-name="Table1.B" />
				<table:table-row>
					<table:table-cell table:style-name="Table1.A1"
						office:value-type="string">
						<text:p text:style-name="P12">
							<text:span text:style-name="T1">
								' . LANG_Tip_camion . ' 
							</text:span>
							' . htmlspecialchars($comanda->fel_camion) . '
						</text:p>
					</table:table-cell>
					<table:table-cell table:style-name="Table1.B1"
						office:value-type="string">
						<text:p text:style-name="P12">
							<text:span text:style-name="T1">
								' . LANG_nr_inmatriculare . '
							</text:span>
							' . htmlspecialchars($comanda->nr_inmatriculare) . '
						</text:p>
					</table:table-cell>
				</table:table-row>
				<table:table-row>
					<table:table-cell table:style-name="Table1.A2"
						office:value-type="string">
						<text:p text:style-name="P12">
							<text:span text:style-name="T1">
								' . LANG_Nume_sofer . '
							</text:span>
							' . htmlspecialchars($comanda->nume_sofer) . '
						</text:p>
					</table:table-cell>
					<table:table-cell table:style-name="Table1.B2"
						office:value-type="string">
						<text:p text:style-name="P12">
							<text:span text:style-name="T1">
								' . LANG_Telefon_sofer . '
							</text:span>
							' . htmlspecialchars($comanda->tel_sofer) . '
						</text:p>
					</table:table-cell>
				</table:table-row>
				<table:table-row>
					<table:table-cell table:style-name="Table1.A2" office:value-type="string">
						<text:p text:style-name="P17">' . LANG_Incarcari . '</text:p>
					</table:table-cell>
					<table:table-cell table:style-name="Table1.B2"
						office:value-type="string">
						<text:p text:style-name="P17">' . LANG_Descarcari . '</text:p>
					</table:table-cell>
				</table:table-row>';
	


    $k = 0;
	foreach ($comanda->adrese_incarcare as $adresa) {
		++$k;
		/*
		 * aici va veni celula pentru adresa de incarcare
		 */
		$content_xml .= '<table:table-row>';
		
		$content_xml .= '
					<table:table-cell table:style-name="Table1.A2" office:value-type="string">
						<text:p text:style-name="P12">
							' . $k . '.
							<text:span text:style-name="T1">
								' . LANG_Data_si_ora_limita . ' ' . htmlspecialchars(getDateForUser($adresa->data, true)) . '
							</text:span>
						</text:p>
						<text:p text:style-name="P13">
							<text:span text:style-name="T1">
								' . LANG_ADRESA . '
							</text:span>
							' . getAdresaAsString($adresa) . '
						</text:p>';
				if (!empty($adresa->nume_firma)) {
					$content_xml .= '<text:p text:style-name="P14">' . 
							LANG_NUME_FIRMA . '
							<text:span text:style-name="T3">
								' . htmlspecialchars($adresa->nume_firma) . '
							</text:span>
						</text:p>';
				}
				if (!empty($adresa->nume_contact) || $adresa->tel_contact) {
					$content_xml .= '<text:p text:style-name="P12">';
						if (!empty($adresa->nume_contact))  {
							$content_xml .= '<text:span text:style-name="T1">' . LANG_Nume_contact . '</text:span>';
							$content_xml .= '<text:span text:style-name="T2"> ' . htmlspecialchars($adresa->nume_contact) . '</text:span>';
						}
						if (!empty($adresa->tel_contact)) {
							$content_xml .= '<text:span text:style-name="T2">,</text:span>';
							$content_xml .= '<text:span text:style-name="T1"> ' . LANG_Telefon_contact . '</text:span>';
							$content_xml .= '<text:span text:style-name="T2"> ' . htmlspecialchars($adresa->tel_contact) . '</text:span>';
						}
					$content_xml .= '</text:p>';
				}
				
				if (!empty($adresa->tip_marfa) || !empty($adresa->nr_colete) || !empty($adresa->greutate)) {
					$content_xml .= '<text:p text:style-name="P12">';
						if (!empty($adresa->tip_marfa)) {
							$content_xml .= '<text:span text:style-name="T1">' . LANG_Tip_marfa . '</text:span>';
							$content_xml .= '<text:span text:style-name="T2"> ' . htmlspecialchars($adresa->tip_marfa) . '</text:span>';
						}
						if (!empty($adresa->nr_colete)) {
							$content_xml .= '<text:span text:style-name="T2">,</text:span>';
							$content_xml .= '<text:span text:style-name="T1"> ' . LANG_Numar_colete . '</text:span>';
							$content_xml .= '<text:span text:style-name="T2"> ' . htmlspecialchars($adresa->nr_colete) . '</text:span>';
						}
						if (!empty($adresa->greutate)) {
							$content_xml .= '<text:span text:style-name="T2">,</text:span>';
							$content_xml .= '<text:span text:style-name="T1"> ' . LANG_Greutate . '</text:span>';
							$content_xml .= '<text:span text:style-name="T2"> ' . htmlspecialchars($adresa->greutate) . '</text:span>';
							
						}
					$content_xml .= '</text:p>';
				}
				if (!empty($adresa->alte_mentiuni)) {
					$content_xml .= '<text:p text:style-name="P12">
							<text:span text:style-name="T1">
								' . LANG_Mentiuni . '
							</text:span>
							<text:span text:style-name="T2">
								' . htmlspecialchars($adresa->alte_mentiuni) . '
							</text:span>
						</text:p>';
				}
				$content_xml .= '</table:table-cell>';
		
		/*
		 * iau adresele de descarcare pentru adresa de incarcare curenta
		 */
		
		$content_xml .= '<table:table-cell table:style-name="Table1.B2" office:value-type="string">';
		
		
		$adrese_descarcare = array();
		
		$adrese_descarcare_for_incarcare = getAdreseForIncarcare($comanda->adrese_descarcare, $k);
        $adrese_descarcare_fara_incarcare_precizata = getAdreseFaraIncarcare($comanda->adrese_descarcare);
        
		foreach ($adrese_descarcare_fara_incarcare_precizata as $adr) {
			$adrese_descarcare[] = $adr;
		}
		
		foreach ($adrese_descarcare_for_incarcare as $adr) {
			$adrese_descarcare[] = $adr;
		}		

		if (!empty($adrese_descarcare)) {
            $j = 1;
			foreach ($adrese_descarcare as $adresa_descarcare) {
				$content_xml .= '						
							<text:p text:style-name="P12">
								' . $j++ . '.
								<text:span text:style-name="T1">
									' . LANG_Data_si_ora_limita . ' ' . htmlspecialchars(getDateForUser($adresa_descarcare->data, true)) . '
								</text:span>
							</text:p>
							<text:p text:style-name="P13">
								<text:span text:style-name="T1">
									' . LANG_ADRESA . '
								</text:span>
								' . getAdresaAsString($adresa_descarcare) . '
							</text:p>
                            <text:p text:style-name="P12">';
                if ($adresa_descarcare->nume_firma != null && $adresa_descarcare->nume_firma != '')
                $content_xml .= LANG_NUME_FIRMA . '
								<text:span text:style-name="T3">
									' . htmlspecialchars($adresa_descarcare->nume_firma) . '
								</text:span>';
                if ($adresa_descarcare->nume_contact != null && $adresa_descarcare->nume_contact != '')
                $content_xml .= '
                				<text:span text:style-name="T2">,</text:span>
								<text:span text:style-name="T1">
									' . LANG_Nume_contact . '
								</text:span>
								<text:span text:style-name="T2">
									' . htmlspecialchars($adresa_descarcare->nume_contact) . '
								</text:span>';
                if ($adresa_descarcare->tel_contact != null && $adresa_descarcare->tel_contact != '')
                $content_xml .= '
                				<text:span text:style-name="T2">,</text:span>
								<text:span text:style-name="T1">
									' . LANG_Telefon_contact . '
								</text:span>
								<text:span text:style-name="T2">
									' . htmlspecialchars($adresa_descarcare->tel_contact) . '
								</text:span>';
                if ($adresa_descarcare->tip_marfa != null && $adresa_descarcare->tip_marfa != '')
                $content_xml .= '
                				<text:span text:style-name="T2">,</text:span>
								<text:span text:style-name="T1">
									' . LANG_Tip_marfa . '
								</text:span>
								<text:span text:style-name="T2">
									' . htmlspecialchars($adresa_descarcare->tip_marfa) . '
								</text:span>';
                if ($adresa_descarcare->nr_colete != null && $adresa_descarcare->nr_colete != '')
                $content_xml .= '
                				<text:span text:style-name="T2">,</text:span>
								<text:span text:style-name="T1">
									' . LANG_Numar_colete . '
								</text:span>
								<text:span text:style-name="T2">
									' . htmlspecialchars($adresa_descarcare->nr_colete) . '
								</text:span>';
                if ($adresa_descarcare->greutate != null && $adresa_descarcare->greutate != '')
                $content_xml .= '
                				<text:span text:style-name="T2">,</text:span>
								<text:span text:style-name="T1">
									' . LANG_Greutate . '
								</text:span>
								<text:span text:style-name="T2">
									' . htmlspecialchars($adresa_descarcare->greutate) . '
								</text:span>';
				if ($adresa_descarcare->alte_mentiuni != null && $adresa_descarcare->alte_mentiuni != '')
                $content_xml .= '
                				<text:span text:style-name="T2">,</text:span>
								<text:span text:style-name="T1">
									' . LANG_Mentiuni . '
								</text:span>
								<text:span text:style-name="T2">
									' . htmlspecialchars($adresa_descarcare->alte_mentiuni) . '
								</text:span>';
                $content_xml .= '
							</text:p>';
			}				
		}	
		$content_xml .= '</table:table-cell>';
		$content_xml .= '</table:table-row>';
	}
	$content_xml .= '									
				<table:table-row>
					<table:table-cell table:style-name="Table1.A2"
						office:value-type="string">
						<text:p text:style-name="P17">
							 ' . LANG_Vama_export . '
						</text:p>
					</table:table-cell>
					<table:table-cell table:style-name="Table1.B2"
						office:value-type="string">
						<text:p text:style-name="P17">
							' . LANG_Vama_import . '
						</text:p>
					</table:table-cell>
				</table:table-row>
				<table:table-row>
					<table:table-cell table:style-name="Table1.A2" office:value-type="string">';
	
	foreach ($comanda->adrese_vama_export as $vama_export) {  
			if (!empty($vama_export->legatura_incarcare)) {
            	$content_xml .= '        
                        <text:p text:style-name="P13">
                            <text:span text:style-name="T1">
                                ' . LANG_Marfa_incarcata_la_locul . '
                            </text:span>
                                ' . htmlspecialchars($vama_export->legatura_incarcare) . '
                        </text:p>';				
			}    
			          
            $content_xml .= '           
                        <text:p text:style-name="P13">
                            <text:span text:style-name="T1">
                                ' . LANG_ADRESA . '
                            </text:span>
                            ' . getAdresaAsString($vama_export) . '
                        </text:p>';
            
            if (!empty($vama_export->impexp)) {
            	$content_xml .= '
            	        <text:p text:style-name="P15">
                            <text:span text:style-name="T1">
                                ' . LANG_Nume_importator . '
                            </text:span>
                            ' . htmlspecialchars($vama_export->impexp) . '
                        </text:p>';
            }
            
            if (!empty($vama_export->nume_firma)) {
            	$content_xml .= '
                        <text:p text:style-name="P15">
                            <text:span text:style-name="T1">
                                ' . LANG_Comisionar_vamal . '
                            </text:span>
                            ' . htmlspecialchars($vama_export->nume_firma) . '
                        </text:p>';
            }
            if (!empty($vama_export->nume_contact) || !empty($vama_export->tel_contact)) {
				$content_xml .= '<text:p text:style-name="P15">';
					if (!empty($vama_export->nume_contact)) {
						$content_xml .= '<text:span text:style-name="T1">' . LANG_NUME_CONTACT . '</text:span>';
						$content_xml .= htmlspecialchars($vama_export->nume_contact);
					}
					if (!empty($vama_export->tel_contact)) {
						$content_xml .= '<text:span text:style-name="T1">' . LANG_Telefon_contact . '</text:span>';
	                 	$content_xml .= htmlspecialchars($vama_export->tel_contact);
					}
				$content_xml .= '</text:p>';
            }
			
            if (!empty($vama_export->nume_birou_vamal) || !empty($vama_export->cod_vama)) {
				$content_xml .= '<text:p text:style-name="P15">';
					if (!empty($vama_export->nume_birou_vamal)) {
						$content_xml .= '<text:span text:style-name="T1">' . LANG_Nume_birou_vamal . '</text:span>';
	                    $content_xml .= '<text:span text:style-name="T3">' . htmlspecialchars($vama_export->nume_birou_vamal) . '</text:span>';
					}
	                if (!empty($vama_export->cod_vama)) {
	                	$content_xml .= '<text:span text:style-name="T1">' . LANG_Cod_vama . '</text:span>';
	                    $content_xml .= htmlspecialchars($vama_export->cod_vama);
	                }
	            $content_xml .= '</text:p>';
            }

			if (!empty($vama_export->alte_mentiuni)) {			
				$content_xml .= '
                        <text:p text:style-name="P15">
                            <text:span text:style-name="T1">
                                ' . LANG_Mentiuni . '
                            </text:span>
                            ' . htmlspecialchars($vama_export->alte_mentiuni) . '
                        </text:p>';
			}			
    }
    
	$content_xml .= '
					</table:table-cell>
					<table:table-cell table:style-name="Table1.B2" office:value-type="string">';
		foreach ($comanda->adrese_vama_import as $vama_import) {
			if (!empty($vama_import->legatura_incarcare)) {
            	$content_xml .= '        
                        <text:p text:style-name="P13">
                            <text:span text:style-name="T1">
                                ' . LANG_Marfa_incarcata_la_locul . '
                            </text:span>
                                ' . htmlspecialchars($vama_import->legatura_incarcare) . '
                        </text:p>';				
			}    
			          
            $content_xml .= '           
                        <text:p text:style-name="P13">
                            <text:span text:style-name="T1">
                                ' . LANG_ADRESA . '
                            </text:span>
                            ' . getAdresaAsString($vama_import) . '
                        </text:p>';
            
            if (!empty($vama_import->impexp)) {
            	$content_xml .= '
            	        <text:p text:style-name="P15">
                            <text:span text:style-name="T1">
                                ' . LANG_Nume_importator . '
                            </text:span>
                            ' . htmlspecialchars($vama_import->impexp) . '
                        </text:p>';
            }
            
            if (!empty($vama_import->nume_firma)) {
            	$content_xml .= '
                        <text:p text:style-name="P15">
                            <text:span text:style-name="T1">
                                ' . LANG_Comisionar_vamal . '
                            </text:span>
                            ' . htmlspecialchars($vama_import->nume_firma) . '
                        </text:p>';
            }
            if (!empty($vama_import->nume_contact) || !empty($vama_import->tel_contact)) {
				$content_xml .= '<text:p text:style-name="P15">';
					if (!empty($vama_import->nume_contact)) {
						$content_xml .= '<text:span text:style-name="T1">' . LANG_NUME_CONTACT . '</text:span>';
						$content_xml .= htmlspecialchars($vama_import->nume_contact);
					}
					if (!empty($vama_import->tel_contact)) {
						$content_xml .= '<text:span text:style-name="T1">' . LANG_Telefon_contact . '</text:span>';
	                 	$content_xml .= htmlspecialchars($vama_import->tel_contact);
					}
				$content_xml .= '</text:p>';
            }
			
            if (!empty($vama_import->nume_birou_vamal) || !empty($vama_import->cod_vama)) {
				$content_xml .= '<text:p text:style-name="P15">';
					if (!empty($vama_import->nume_birou_vamal)) {
						$content_xml .= '<text:span text:style-name="T1">' . LANG_Nume_birou_vamal . '</text:span>';
	                    $content_xml .= '<text:span text:style-name="T3">' . htmlspecialchars($vama_import->nume_birou_vamal) . '</text:span>';
					}
	                if (!empty($vama_import->cod_vama)) {
	                	$content_xml .= '<text:span text:style-name="T1">' . LANG_Cod_vama . '</text:span>';
	                    $content_xml .= htmlspecialchars($vama_import->cod_vama);
	                }
	            $content_xml .= '</text:p>';
            }

			if (!empty($vama_import->alte_mentiuni)) {			
				$content_xml .= '
                        <text:p text:style-name="P15">
                            <text:span text:style-name="T1">
                                ' . LANG_Mentiuni . '
                            </text:span>
                            ' . htmlspecialchars($vama_import->alte_mentiuni) . '
                        </text:p>';
			}						
    }
    
	$content_xml .= '		
					</table:table-cell>
				</table:table-row>
				<table:table-row>
					<table:table-cell table:style-name="Table1.B2"
						table:number-columns-spanned="2" office:value-type="string">
						<text:p text:style-name="P16">
                            <text:p text:style-name="P12"/>' . LANG_Alte_conditii . '
							<text:span text:style-name="T3">
								' . htmlspecialchars($comanda->alte_conditii) . '
							</text:span>
						</text:p>
					</table:table-cell>
					<table:covered-table-cell />
				</table:table-row>
				<table:table-row>
					<table:table-cell table:style-name="Table1.B2"
						table:number-columns-spanned="2" office:value-type="string">
						<text:p text:style-name="P12">
							<text:span text:style-name="T1">
								' . LANG_Pret_negociat_si_acceptat . '
							</text:span>: '. $comanda->suma_totala_exec . ' ' . $currencies[$comanda->moneda_exec];
	if ($comanda->tva_inclus_exec)
    $content_xml .= '        
    						<text:span text:style-name="T1">
								' . LANG_totul_inclus . '
							</text:span>';
    $content_xml .= '
						</text:p>
					</table:table-cell>
					<table:covered-table-cell />
				</table:table-row>
				<table:table-row>
					<table:table-cell table:style-name="Table1.B2"
						table:number-columns-spanned="2" office:value-type="string">
						<text:p text:style-name="P12">
							<text:span text:style-name="T1">
								' . LANG_Termenul_de_plata . ':
							</text:span>
							' . $comanda->zile_scadenta_exec . ' ' . LANG_zile .'
						</text:p>
					</table:table-cell>
					<table:covered-table-cell />
				</table:table-row>
			</table:table>';
?>			